package web

import (
	"container/list"
)

//
// 网页终端连接管理
//
var MemWorker = list.New()


// 添加worker
func insertWorker(w *Worker) error {
	if w != nil {
		MemWorker.PushBack(w)
	}
	return nil
}


// 删除worker
func removeWorker(w *Worker) error {
	if w != nil {
		for e := MemWorker.Front(); e != nil; e = e.Next() {
			if e.Value == w {
				MemWorker.Remove(e)
				break
			}
		}
	}
	return nil
}

//
// 向worker 发送任务
//
func postNotify(memId string, buffer []byte) error {
	for e := MemWorker.Front(); e != nil; e = e.Next() {
		w, ok := e.Value.(*Worker)
		if ok {
			if w.memberId == memId {
				w.Notify(buffer)
			}
		}
	}
	return nil
}

